home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Search Proc [insp] Example / myFileSearchProc.r < prev    next >
Encoding:
Text File  |  1996-09-23  |  11.8 KB  |  410 lines  |  [TEXT/MPS ]

  1. //
  2. //    myFileSearchProc.r
  3. //        
  4. //    The example file search proc uses TYPE and CREATOR to determine 
  5. //    list of matching files on target volume, rather than searching on filename.
  6. //    Your search procedure ( code resource ) can use any approach that you wish.
  7. //    We have chosen a relatively simple method for sake of simplicity. Our search
  8. //    procedure example does not exclude files in the trash or files in any
  9. //    installer temp folders that might exist in the system folder of the 
  10. //    target volume. 
  11. //
  12. //    Extra 'vers' resources of ID # (3) and (4) have been added to the source 
  13. //    "SimpleText" file contained within subfolder "Disk 1:" so that the "original" 
  14. //    and "replaced" copies of "SimpleText" ( on target volume )
  15. //    can be distinguished from each other.
  16. //
  17. //    Search procedures can be used to select files to be replaced, or can
  18. //    be used within the rule framework to add Easy Install or Custom Install
  19. //    packages depending on whether or not a file exists on the target volume.
  20. //    Search procedures can also be used within the rule framework to display
  21. //    an error message, warning the user that installation cannot be performed
  22. //    to the selected target volume because a certain file does not exist on
  23. //    the target volume. This feature is especially useful when performing
  24. //    upgrades of application or system software.
  25. //
  26. //    IMPORTANT: With Installer 4.0.3 the only atoms that support the file 
  27. //    search procedure are file ( 'infa' ) and resource ( 'inra' ) atoms. The 
  28. //    FolderMerge ( 'infm' ) and ResMerge ( 'inrm' ) atoms are not supported.
  29. //    Even if one of the unsupported atoms uses a target spec ( 'intf' ) that 
  30. //    includes a file search proc, the normal file search mechanism will be
  31. //    used when processing the unsupported atom.
  32. //
  33. //    There are four packages in this example script. Each package utilizes
  34. //    a sample file search procedure that overrides the default search path
  35. //    for Installer 4.x. Each package generates one custom install option 
  36. //    for each of the following example cases:
  37. //
  38. //    1) file atom - delete on install, copy on install
  39. //
  40. //        This option first deletes all found copies of "TeachText" and "SimpleText"
  41. //        ( as well as any other files with Type 'APPL' and Creator 'ttxt' )
  42. //        from the target volume ( making backups to "InstallerTemp:" during
  43. //        live-install ), then copies the "SimpleText" application contained in the
  44. //        subfolder "Disk 1:" to the target volume to replace all found copies
  45. //        of "TeachText" and "SimpleText". 
  46. //
  47. //    2) file atom - delete on install, but don't copy on install
  48. //
  49. //        This option deletes all found copies of "TeachText" and "SimpleText"
  50. //        ( as well as any other files with Type 'APPL' and Creator 'ttxt' )
  51. //        from the target volume ( making backups to "InstallerTemp:" during
  52. //        live-install ).
  53. //
  54. //    3) resource atom - delete on install, copy on install
  55. //
  56. //        This option first deletes the resource 'vers' (4) from all found
  57. //        copies of "TeachText" and "SimpleText" ( as well as any other files 
  58. //        with Type 'APPL' and Creator 'ttxt' ) on the target volume ( making 
  59. //        backups to "InstallerTemp:" during live-install ), then copies the 
  60. //        'vers' (4) resource item from within the "SimpleText" application 
  61. //        contained in the subfolder "Disk 1:" to each copy of "TeachText"
  62. //        and "SimpleText" found on the target volume.
  63. //
  64. //    4) resource atom - delete on install, but don't copy on install
  65. //
  66. //        This option deletes the resource 'vers' (4) from all found
  67. //        copies of "TeachText" and "SimpleText" on the target volume ( making 
  68. //        backups to "InstallerTemp:" during live-install ).
  69. //
  70.  
  71. #include "InstallerTypes.r"
  72.  
  73. // include the 'infn' code resource containing file searching procedure
  74. include "FindTargetFile.rsrc";
  75.  
  76.  
  77.  
  78. // • framework and rules
  79.  
  80. // custom install framework always uses ID# 766
  81.  
  82. // Custom Install framework fires both rules listed below
  83. resource 'infr' ( kCustomInstallFrameworkRsrcID ) {
  84.     format0 {{
  85.         pickAll, { 100,500 },
  86.     }}
  87. };
  88.  
  89. // add the first four custom install packages
  90. resource 'inrl' ( 100 ) {
  91.     format0 {{
  92.         AddCustomItems {{ 100,200,300,400 }}            
  93.     }};
  94. };
  95.  
  96. // reference 'insp' ( file search proc ) 
  97. // contained within 'intf' ( target file spec )
  98. resource 'inrl' ( 500 ) {
  99.     format0 {{
  100.         checkFileRsrcForkExists { 10001 },    // add the last package only if
  101.         AddCustomItems {{ 500 }}            // the rule above returned true
  102.     }};
  103. };
  104.  
  105.  
  106. // • packages
  107.  
  108. // package for file search proc
  109. // w/ file atoms - delete on install, copy on install
  110. resource 'inpk' (100) {
  111.     format0 {
  112.         showsOnCustom,
  113.         removable,
  114.         dontForceRestart,
  115.         0,
  116.         0,
  117.         "Remove, then Replace all copies of “SimpleText” on target volume.",
  118.         {    
  119.         'infa', 1000    
  120.         },
  121.     }
  122. };
  123.  
  124. // package for file search proc
  125. // w/ file atoms - delete on install, but don't copy on install
  126. resource 'inpk' (200) {
  127.     format0 {
  128.         showsOnCustom,
  129.         removable,
  130.         dontForceRestart,
  131.         0,
  132.         0,
  133.         "Remove all copies of “SimpleText” on target volume.",
  134.         {    
  135.         'infa', 2000    
  136.         },
  137.     }
  138. };
  139.  
  140.  
  141. // package for file search proc
  142. // w/ resource atoms - delete on install, copy on install
  143. resource 'inpk' (300) {
  144.     format0 {
  145.         showsOnCustom,
  146.         removable,
  147.         dontForceRestart,
  148.         0,
  149.         0,
  150.         "Add/Replace 'vers' (4) resource to all copies of “SimpleText” on tgt vol.",
  151.         {    
  152.         'inra', 3000    
  153.         },
  154.     }
  155. };
  156.  
  157.  
  158. // package for file search proc
  159. // w/ resource atoms - delete on install, but don't copy on install
  160. resource 'inpk' (400) {
  161.     format0 {
  162.         showsOnCustom,
  163.         removable,
  164.         dontForceRestart,
  165.         0,
  166.         0,
  167.         "Remove 'vers' (4) resource from all copies of “SimpleText” on tgt vol.",
  168.         {    
  169.         'inra', 4000    
  170.         },
  171.     }
  172. };
  173.  
  174. // this last package just provides an easy way to see if the
  175. // second rule in the Custom Install framework returned true.
  176.  
  177. // package for file search proc
  178. // utilizes 'insp' from within installer rule framework
  179. resource 'inpk' (500) {
  180.     format0 {
  181.         showsOnCustom,
  182.         notRemovable,
  183.         dontForceRestart,
  184.         0,
  185.         0,
  186.         "Rule calling 'insp' via 'intf' succeeded ( or I'd not be here ) !!",
  187.         {    
  188.         'infa', 1000    
  189.         },
  190.     }
  191. };
  192.  
  193. // • file atoms
  194.  
  195. // file atom for file seach proc, remove and replace during install
  196. resource 'infa' (1000) {
  197.     format1 {
  198.         deleteWhenRemoving,
  199.         deleteWhenInstalling,
  200.         copy,                        
  201.         dontIgnoreLockedFile,
  202.         dontSetFileLocked,
  203.         useVersProcToCompare,        
  204.         srcNeedExist,
  205.         rsrcForkInRsrcFork,
  206.         leaveAloneIfNewer,            
  207.         updateExisting,                
  208.         copyIfNewOrUpdate,
  209.         rsrcFork,
  210.         dataFork,
  211.         0,
  212.         0x0,
  213.         10001,
  214.         {    
  215.             10000, 
  216.             0, 
  217.             0    
  218.         },
  219.         0,                        
  220.         0,
  221.         0,
  222.         "SimpleText"
  223.     }
  224. };
  225.  
  226. // file atom for file seach proc, remove but don't copy during install
  227. resource 'infa' (2000) {
  228.     format1 {
  229.         deleteWhenRemoving,
  230.         deleteWhenInstalling,
  231.         dontCopy,                    //  • don't Copy during Install
  232.         dontIgnoreLockedFile,
  233.         dontSetFileLocked,
  234.         useVersProcToCompare,        //  Use version proc for compare
  235.         srcNeedExist,
  236.         rsrcForkInRsrcFork,
  237.         leaveAloneIfNewer,            //  Do not update a newer file
  238.         updateExisting,                //  Update an existing file
  239.         copyIfNewOrUpdate,
  240.         rsrcFork,
  241.         dataFork,
  242.         0,
  243.         0x0,
  244.         10001,
  245.         {    
  246.             10000, 
  247.             0, 
  248.             0    
  249.         },
  250.         0,                            
  251.         0,
  252.         0,
  253.         "SimpleText"
  254.     }
  255. };
  256.  
  257. // • resource atoms
  258.  
  259. // resource atom for file seach proc; remove, copy during install
  260. resource 'inra' (3000) {
  261.     format1 {
  262.         deleteWhenRemoving,
  263.         deleteWhenInstalling,
  264.         copy,                        // Copy during Install
  265.         leaveAloneIfNewer,            // Do not update a newer file
  266.         tgtRequired,                // Don't allow install unless target exists
  267.         updateExisting,                // Update an existing file
  268.         copyIfNewOrUpdate,            // Make or replace
  269.         dontIgnoreProtection,        // Respect those protected bits
  270.         srcNeedExist,                // Source must exist on install disk
  271.         
  272.         byID,                        // Reference resource by ID #
  273.         nameNeedNotMatch,            // Only use ID # for target of resource
  274.         
  275.         0,                             
  276.         10001,                        // Target file spec
  277.         'vers',                        // Target resource type
  278.         4,                            // Target resource ID #
  279.         0x0,                        // Target resource attributes
  280.         "resource search proc",        // Target resource name
  281.         {
  282.             10000,                    // Source file spec
  283.             'vers',                    // Source piece type
  284.             4,                        // Source piece ID #
  285.             0,                        // Target piece size
  286.             "",                        // Source piece resource name
  287.         },
  288.         0x0,                        // Source version #
  289.         0,                            // Version compare resource number
  290.         0,                            // Atom extender resource ID
  291.         ""                            // Total target size
  292.     }
  293. };
  294.  
  295.  
  296. // resource atom for file seach proc; remove, but don't copy during install
  297. resource 'inra' (4000) {
  298.     format1 {
  299.         deleteWhenRemoving,
  300.         deleteWhenInstalling,
  301.         dontCopy,                    // Don't copy during Install
  302.         leaveAloneIfNewer,            // Do not update a newer file
  303.         tgtRequired,                // Don't allow install unless target exists
  304.         updateExisting,                // Update an existing file
  305.         copyIfNewOrUpdate,            // Make or replace
  306.         dontIgnoreProtection,        // Respect those protected bits
  307.         srcNeedExist,                // Source must exist on install disk
  308.         byID,                        // Reference resource by ID #
  309.         nameNeedNotMatch,            // Existing resource referenced by ID # 
  310.                                     // must have same name to be replaced.
  311.         0,                             
  312.         10001,                        // Target file spec
  313.         'vers',                        // Target resource type
  314.         4,                            // Target resource ID #
  315.         0x0,                        // Target resource attributes
  316.         "resource search proc",        // Target resource name
  317.         {
  318.             10000,                    // Source file spec
  319.             'vers',                    // Source piece type
  320.             4,                        // Source piece ID #
  321.             0,                        // Target piece size
  322.             "",                        // Source piece resource name
  323.         },
  324.         0x0,                        // Source version #
  325.         0,                            // Version compare resource number
  326.         0,                            // Atom extender resource ID
  327.         ""                            // Total target size
  328.     }
  329. };
  330.  
  331.  
  332. // • file specs
  333.  
  334. // target file spec for file search atom
  335. resource 'intf' (10001) {
  336.     format1 {
  337.         searchForFile,                    // • override default search path
  338.         
  339.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  340.                                         // then a file with a different type
  341.                                         // and creator than those specified
  342.                                         // below will not be replaced.
  343.                                         // If this is set to TypeCrNeedNotMatch
  344.                                         // then type and creator of an existing
  345.                                         // target file are ignored.
  346.         
  347.         // The Type and Creator fields will be used to set the
  348.         // file's Type and Creator when a new file is created. 
  349.         'APPL',                         // TYPE for new file
  350.         'ttxt',                         // CREATOR for new file
  351.         
  352.         0,                                 // finder attribute flags
  353.                                         // filled by ScriptCheck is value is 0
  354.         
  355.         1,                                  // creation date for new file
  356.         1,                                  // modification date for new file
  357.                                         // NOTE: DATE values are filled
  358.                                         // by ScriptCheck if the value is 1
  359.                                             
  360.         200,                            // • 'insp' resource ID ( file search proc )
  361.         
  362.         ":SimpleText"                    // path to target file
  363.         }
  364.     };
  365.  
  366. // source file spec for file search atom
  367. resource 'infs' (10000) {
  368.     'APPL',                        // TYPE for source file
  369.     'ttxt',                        // CREATOR for source file
  370.     0x1,                        // creation DATE for source file
  371.     searchForFile,                // IGNORED in Installer 4.0.x
  372.     TypeCrMustMatch,            // TYPE, CREATOR must match file on install disk
  373.     "Disk 1:SimpleText"            // PATH to source file        
  374. };
  375.  
  376.  
  377. // • interface to search proc
  378.  
  379. // file search proc
  380. resource 'insp' (200) {
  381.     format0 {
  382.         'infn',                    // SEARCH PROC • Code Rsrc Type
  383.         20,                        // SEARCH PROC • Code Rsrc ID
  384.                                 // NOTE: The code resource type and ID
  385.                                 // values are specified within the makefile 
  386.                                 // for the search proc code resource. 
  387.                                 // In this example the lines that create the 
  388.                                 // search proc code resource are in the same 
  389.                                 // makefile as the one that builds the installer 
  390.                                 // script. You should use the values specified 
  391.                                 // in the makefile to fill in these fields.
  392.                                 
  393.         0,                        // SEARCH PROC • RefCon
  394.                                 // NOTE: This value will be passed
  395.                                 // into your search proc code resource
  396.                                 // when the search procedure is called.
  397.                                 
  398.         0,                        // SEARCH PROC • Min Required Memory
  399.                                 // NOTE: Set this value to 0 to use
  400.                                 // the installer's allocate memory.
  401.                                 // Unless your search proc code resource
  402.                                 // has specific need for its own memory
  403.                                 // heap you should always set this
  404.                                 // value to 0.
  405.                                 
  406.         "Searching for all files."    
  407.                                 // SEARCH PROC • Description
  408.     }
  409. };
  410.